<template>
	<view>
		<view style="clear: both;width: 100vw;overflow: scroll;" v-if="showTable">
			<zb-table :show-header="true" :columns="column" :stripe="false" :fit="false" @rowClick="rowClick"
				:tableForm="tableForm" @toggleRowSelection="toggleRowSelection" @toggleAllSelection="toggleAllSelection"
				:border="true" @edit="buttonEdit" :data="tableData"></zb-table>
		</view>
		<view v-if="showtableform">
			<u-modal width="750rpx" showCancelButton @cancel="showtableform=false" @confirm="saveTableform" :show="showtableform"
				title="表格编辑">
				<view style="width:100%">
					<u-form labelPosition="left" :model="editTableForm" ref="tabledefaultform">
						<view v-for="(table, index) in tableForm" :key="index">
							<u-form-item borderBottom :labelWidth="180" :label="table.label" :prop="table.vModel"
								:rules="[{ required: (formAuth[table.vModel]==2&&table.required)?true:false, message: table.placeholder, trigger: table.tag==='el-select'?'change':'blur' }]">
								<view v-if="table.tag==='el-input'&&table.type!=='textarea'">
									<u-input border="surround" :disabled="table.disabled"
										:style="table.style.width?table.style:defaultStyle"
										:maxlength="table.maxlength?table.maxlength:256"
										:placeholder="table.placeholder" v-model="editTableForm[table.vModel]">
									</u-input>
								</view>
								<view v-if="table.tag=='el-select'">
									<view>
										<view style="width: 70%;float: left;">
											{{getSelectDatas(editTableForm[table.vModel],table.options)}}
										</view>
										<view v-show="!table.disabled" @click="openSelect(table.vModel,table.options)"
											 style="width: 50rpx;float: right;">
											<u-icon color="#666" slot="right" name="arrow-right"></u-icon>
											</view>
									</view>
								</view>
								<view v-if="table.tag=='el-switch'">
									<u-switch :disabled="table.disabled" :placeholder="table.placeholder"
										v-model="editTableForm[table.vModel]">
									</u-switch>
								</view>
								<view v-if="table.tag=='fc-date-duration'">
									<view>
										<view style="width: 70%;float: left;">
											<view v-for="im in editTableForm[table.vModel]">
												{{im}}
											</view>
										</view>
										<view v-show="!table.disabled" @click="openRangeDate(table.vModel)"
										 style="width: 50rpx;float: right;">
											<u-icon color="#666" slot="right" name="arrow-right"></u-icon>
											</view>
									</view>
									<view v-if="showRange">
										<u-calendar :show="showRange" :mode="mode" @confirm="confirmRangeDate"
											@close="showRange=false"></u-calendar>
									</view>
								</view>
								<view v-if="table.tag=='el-date-picker'">
									<view>
										<view style="width: 70%;float: left;">
											{{editTableForm[table.vModel]?editTableForm[table.vModel]:""}}
										</view>
										<view v-show="!table.disabled" @click="openSingleDate(table.vModel)"
										 style="width: 50rpx;float: right;">
											<u-icon color="#666" slot="right" name="arrow-right"></u-icon>
											</view>
									</view>
									<view v-if="showSingle">
										<u-calendar :show="showSingle" :disabled="table.disabled" :mode="mode"
											@confirm="confirmSingleDate" @close="showSingle=false"></u-calendar>
									</view>
								</view>
								<view v-if="table.tag=='fc-time-duration'">
									<view>
										<view style="width: 70%;float: left;">
											<view v-for="it in editTableForm[table.vModel]">
												{{it}}
											</view>
										</view>
										<view v-show="!table.disabled" @click="opendurationTime(table.vModel)"
										 style="width: 50rpx;float: right;">
											<u-icon color="#666" slot="right" name="arrow-right"></u-icon>
											</view>
									</view>
									<view v-if="showdurationtime">
										<u-modal :showConfirmButton="false" :show="showdurationtime" title="时间范围">
											<view style="width:100%">
												<smh-time-range :time="['12','30','0','17','30']"
													@confrim="confrimTimeDuration"
													@cancel="cancelTimeDuration"></smh-time-range>
											</view>
										</u-modal>
									</view>
								</view>
								<view v-if="table.tag=='el-slider'">
									<u-slider style="position: :disabled=" table.disabled" relative;left: -40rpx;"
										:min="table.min" :max="table.max" :step="table.step"
										:value="editTableForm[table.vModel]"></u-slider>
								</view>
								<view v-if="table.tag=='el-radio-group'">
									<radio-group @change="changeRadio" :data-vModel="table.vModel" :data-index="i"
										:disabled="table.disabled">
										<label style="transform:scale(0.7);" v-for="(it, ind) in table.options"
											:key="it.value">
											<view style="float: left;transform:scale(0.7);">
												<radio :disabled="table.disabled" :value="it.value"
													:checked="it.value === editTableForm[table.vModel]" />
												{{it.label}}
											</view>
										</label>
									</radio-group>
								</view>
								<view v-if="table.tag=='el-checkbox-group'">
									<u-checkbox-group @change="$forceUpdate()" :disabled="table.disabled" size="30"
										:labelSize="30" v-model="editTableForm[table.vModel]">
										<u-checkbox style="width: 100%;" v-for="(check, ind) in table.options"
											:labelSize="30" :key="check.value" :label="check.label" :name="check.value">
										</u-checkbox>
									</u-checkbox-group>
								</view>
								<view v-if="table.tag=='el-input-number'">
									<u-input border="surround" :disabled="table.disabled"
										:style="table.style.width?table.style:defaultStyle" type="number"
										:placeholder="table.placeholder" v-model="editTableForm[table.vModel]">
									</u-input>
								</view>
								<view v-if="table.tag=='el-rate'">
									<uni-rate size="30" :disabled="table.disabled"
										v-model="editTableForm[table.vModel]" />
								</view>
								<view v-if="table.tag==='el-input'&&table.type==='textarea'">
									<u-input :disabled="table.disabled"
										:style="table.style.width?table.style:defaultStyle" :rows="2"
										:maxlength="table.maxlength?table.maxlength:256"
										:placeholder="table.placeholder" :autosize="table.autosize"
										:show-word-limit="editTableForm['show-word-limit']"
										v-model="editTableForm[table.vModel]"></u-input>
								</view>
								<view v-if="table.tag=='fc-amount'">
									<u-input border="surround" :disabled="table.disabled"
										:style="table.style.width?table.style:defaultStyle" type="number"
										:placeholder="table.placeholder" v-model="editTableForm[table.vModel]">
									</u-input>
								</view>
								<view v-if="table.tag=='el-time-picker'">
									<view>
										<view style="width: 70%;float: left;">
											{{editTableForm[table.vModel]?editTableForm[table.vModel]:""}}
										</view>
										<view v-show="!table.disabled" @click="openSingleTime(table.vModel)"
										 style="width: 50rpx;float: right;">
											<u-icon color="#666" slot="right" name="arrow-right"></u-icon>
											</view>
									</view>
									<view v-if="showSingletime">
										<u-popup :show="showSingletime" @close="showSingletime=false">
											<view style="width:100%">
												<singleTime :time="['12','30','0','17','30']"
													@confrim="confrimSingleTime" @cancel="cancelSingleTime">
												</singleTime>
											</view>
										</u-popup>
									</view>
								</view>
								<view v-if="table.tag=='el-upload'" @click="beforeRead(table)">
									<u-upload :fileList="fileList" @afterRead="afterRead" name="1" multiple
										:maxCount="10"></u-upload>
									<view v-if="editTableForm[table.vModel]">
										<view v-for="(files,index) in editTableForm[table.vModel]">
											<view class="fileStyle" @click="downloadFile(files)">
												{{files.originalFileName}}
											</view>
											<!-- <a @click="showFiles(files.fileName,files.originalFileName)">{{ files.originalFileName }}</a> -->
										</view>
									</view>
								</view>
							</u-form-item>
						</view>
					</u-form>
				</view>
			</u-modal>
		</view>
		<view v-if="showTableChildForm" style="height: 80vh;overflow: scroll;padding-bottom: 100rpx;">
			<u-popup :mode="mode" closeable :mask-close-able="false" height="50vh" width="100%" v-model="showTableChildForm"
					border-radius="14" mode="bottom">
					<view style="padding: 80rpx 20rpx;">
						<view v-for="(item,index) in column" :key="index" style="height: auto;width: 100%;clear: all;">
							<view>
								<view style="width: 100%;clear: all;" v-if="getTag(tableForm,item)!='el-upload'">
									<view style="float: left;font-weight: bold;">{{item.label}}：</view>
									<view style="text-align: right;color: #666;word-break: break-all;">
										{{tableChildForm[item.name]?tableChildForm[item.name]:'--'}}
									</view>
								</view>
								<view v-else>
									<view>{{item.label}}：</view>
									<view v-for="it in tableChildForm[item.name]" style="width: 100%;padding: 6rpx;clear: both;height:60rpx;float: right">
										<u-tag @click="showFiles(it.fileName,it.originalFileName)"
											 :text="it.originalFileName" shape="circle" />
									</view>
								</view>
							</view>
						</view>
					</view>
				</u-popup>
			</view>

		<view v-if="showSelect">
			<!-- 选择器 -->
			<u-picker :key="stimer" @cancel="showSelect=false" @confirm="comfirnSelect" :show="showSelect"
				:columns="[selectOptions]" keyName="label"></u-picker>
		</view>
	</view>

</template>

<script>
	import PROVINCE from './province';
	import singleTime from './singleTime.vue'
	import global from '@/plugins/global'
	export default {
		components: {
			singleTime
		},
		name: 'editForm',
		props: {
			formData: {
				type: Object,
				default () {
					return {};
				}
			},
			tableForm: {
				type: Array,
				default () {
					return [];
				}
			},
			formAuth: {
				type: Object,
				default () {
					return {};
				}
			},
			vmodel: {
				type: String,
				default () {
					return "";
				}
			},
			defaultForms: {
				type: Array,
				default () {
					return {};
				}
			},
			defaultData: {
				type: Object,
				default () {
					return {};
				}
			}
		},
		data() {
			return {
				tableChildForm: {},
				showTableChildForm: false,
				showTable: true,
				showtableform: false,
				column: [],
				searchVal: '',
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				loading: false,
				defaultForm: {},
				close1: true,
				notifymessage: '',
				stimer: null,
				fileList: [],
				show: true,
				value1: null,
				mode: 'range',
				timerform: null,
				showRange: false,
				myHeaders: {
					Authorization: '',
					TenantId: 0
				},
				checkModel: {},
				isCheck: false,
				userTimer: '',
				PROVINCE: PROVINCE,
				loading: false,
				defaultStyle: {
					width: '100%'
				},
				fileList: [],
				rules: {},
				fields: [],
				approveData: {},
				selectUserData: {},
				selectedProcessKey: '',
				isEmpty: false,
				mark: '',
				tableMark: null,
				tableIndex: null,
				formTag: '',
				showSingle: false,
				showSingletime: false,
				showSelect: false,
				showdurationtime: false,
				approveForm: {
					'agree': true,
					'comment': '',
					'param': {},
					'procInstId': 0
				},
				selectOptions: [],
				mark: '',
				tableData: [],
				editTableForm: {},
				global:global
			}
		},
		mounted() {
			
			setTimeout(()=>{
				this.defaultForm = this.defaultForms;
				this.tableData = JSON.parse(JSON.stringify(this.defaultForms))
				this.tableForm.forEach(table => {
					this.tableData.forEach(row => {
						if (table.tag == "el-radio-group") {
							table.options.forEach(check => {
								console.log(check, row, row[table['vModel']]);
								if (check.value == row[table['vModel']]) {
									row[table['vModel']] = check.label
								}
							})
						}
						if (table.tag == "el-upload") {
							console.log(row[table['vModel']], 'akdoakdo');
							if (row[table['vModel']]) {
								row[table['vModel']] = '文件*' + row[table['vModel']].length
							}
				
						}
						if (table.tag == "el-checkbox-group") {
							let d = []
							table.options.forEach(check => {
								if (row[table['vModel']]) {
									row[table['vModel']].forEach(c => {
										if (check.value == c) {
											d.push(check.label)
										}
									})
								}
							})
							row[table['vModel']] = d
						}
				
					})
				})
				
				this.tableForm.forEach(e => {
					if (e.tag == "el-switch") {
						this.column.push({
							type: 'switch',
							name: e.vModel,
							label: e.label
						})
					} else {
						this.column.push({
							name: e.vModel,
							label: e.label
						})
					}
				})
				
				// this.column.push({
				// 	name: 'operation',
				// 	type: 'operation',
				// 	label: '操作',
				// 	renders: [{
				// 			name: '编辑',
				// 			func: 'edit' // func 代表子元素点击的事件 父元素接收的事件 父元素 @edit
				// 		},
				// 		{
				// 			name: '删除',
				// 			type: 'warn',
				// 			func: "dele"
				// 		},
				// 	]
				// }, )
				console.log(this.tableData,'akdoajpdjaifj');
			},10)
		},
		methods: {
			getTag(tform,obj){
				if(tform.length){
					let t = tform.filter(e=>{
						return e.vModel==obj.name
					})
					return t.length>0?t[0].tag:''
				}
				return ''
				
			},
			showFiles(e, name) {
				let url = global.BACKEND_URL + '/extension/file/download?fileName=' + e;
				const downloadTask = uni.downloadFile({
					url: url,
					header: {
						'Authorization': 'Bearer ' + uni.getStorageSync('token'),
						'TenantId': '0'
					},
					success: res => {
						if (res.statusCode === 200) {
							this.isShowProgress = false;
						}
						let that = this;
						uni.openDocument({
							filePath: res.tempFilePath,
							fileType: name.split('.')[name.split('.').length-1],
							success: (sus) => {
								console.log('成功打开');
							}
						})
						// uni.saveFile({
						// 	tempFilePath: res.tempFilePath,
						// 	success: function(red) {
						// 		that.isShowProgress = false;
						// 		uni.openDocument({
						// 			filePath: red.savedFilePath,
						// 			fileType: name.split('.')[name.split('.').length-1],
						// 			success: (sus) => {
						// 				console.log('成功打开');
						// 			}
						// 		})
						// 	}
						// });
					}
				})
			
				downloadTask.onProgressUpdate((res) => {
					if (res.progress > 0) {
						this.isShowProgress = true;
					}
					this.progress = res.progress;
					console.log('下载进度：' + res.progress);
					console.log('已下载长度：' + res.totalBytesWritten);
					console.log('文件总长度：' + res.totalBytesExpectedToWrite);
				})
			},
			saveTableform(e) {
				let row = JSON.parse(JSON.stringify(this.editTableForm))
				this.tableForm.forEach(table => {
					if (table.tag == "el-radio-group") {
						table.options.forEach(check => {
							console.log(check, row, row[table['vModel']]);
							if (check.value == row[table['vModel']]) {
								row[table['vModel']] = check.label
							}
						})
					}
					if (table.tag == "el-upload") {
						console.log(row[table['vModel']], 'akdoakdo');
						if (row[table['vModel']]) {
							row[table['vModel']] = '文件*' + row[table['vModel']].length
						}

					}

					if (table.tag == "el-checkbox-group") {
						let d = []
						table.options.forEach(check => {
							if (row[table['vModel']]) {
								row[table['vModel']].forEach(c => {
									if (check.value == c) {
										d.push(check.label)
									}
								})
							}
						})
						row[table['vModel']] = d
					}
				})

				this.defaultForm.push(this.editTableForm)
				this.tableData.push(row)
				this.showtableform = false;

			},
			rowClick(e, index, column) {
				this.tableChildForm = this.defaultForm[index]
				this.showTableChildForm = true;
			},
			toggleRowSelection(e) {
				console.log(e);
			},
			toggleAllSelection(e) {
				console.log(e);
			},
			changeRadio(e) {
				// this.defaultForm[e.target.dataset.index][e.target.dataset.vmodel] = e.detail.value
				console.log('这是选择了radio', this.defaultForm, e.target.dataset, e);
				this.editTableForm[e.target.dataset.vmodel] = e.detail.value;
			},
			gets(ta) {
				console.log(ta, '-----');
			},
			add() {
				let that = this;
				let obj = {};
				this.tableForm.forEach(e => {
					this.$set(obj, e.vModel, !e.defaultValue ? null : e.defaultValue);
				});
				this.editTableForm = obj
				this.showtableform = true;
				// this.defaultForm.push(obj);
			},
			testData(item) {
				this.defaultForm = item;
				console.log(item, '--djaojdoajdoa');
			},
			gettanleform(e) {
				console.log(e);
			},
			actionData() {
				this.approveForm = {
					'agree': true,
					'comment': '',
					'param': {},
					'procInstId': 0
				};
				this.defaultForm = {};
				this.tableForm = {};
				this.defaultForm = {};
				this.rules = {};
				this.fields = [];
				console.log(this.formData);
				this.formData.fields.forEach(field => {
					if (field.dataSources === "dict") {
						uni.$u.http.request({
							url: global.BACKEND_URL + "/base/dict/query/" + field.api,
							method: 'POST',
							data: {},
							header: {
								Authorization: field.token,
								TenantId: 0
							}
						}).then(res => {
							if (res.data.code === "S00000") {
								field.options = [];
								res.data.data.forEach(e => {
									field.options.push({
										label: e.dictName,
										value: e.dictCode,
									});
								});
							}
						});
					} else if (field.dataSources === "api") {
						field.options;
						uni.$u.http.request({
							url: field.api,
							method: 'POST',
							data: {},
							header: {
								Authorization: field.token,
								TenantId: 0,
							},
							success: (res) => {
								field.options = res.data;
							}
						});
					}
					if (field.tag !== 'grid') {
						if (this.formAuth[field.vModel] == 1) {
							field.disabled = true;
							this.fields.push(field);
						} else if (this.formAuth[field.vModel] == 2) {
							field.disabled = false;
							this.fields.push(field);
						} else if (this.formAuth[field.vModel] == undefined) {
							field.disabled = true;
							this.fields.push(field);
						} else {
							field.hide = true;
						}
						// this.fields.push(field);
						this.$set(this.defaultForm, field.vModel, field.defaultValue == undefined ? null : field
							.defaultValue);
					} else {
						field.children.forEach(e => {
							if (this.formAuth[e.vModel] == 1) {
								e.disabled = true;
								this.fields.push(e);
							} else if (this.formAuth[e.vModel] == 2) {
								e.disabled = false;
								this.fields.push(e);
							} else if (this.formAuth[e.vModel] == undefined) {
								e.disabled = true;
								this.fields.push(e);
							} else {
								e.hide = true;
							}
							// this.fields.push(e);
						});
					}
					if (field.tag == "fc-input-table") {
						let obj = {};
						field.children.forEach(e => {
							this.$set(obj, e.vModel, !e.defaultValue ? null : e.defaultValue);
							this.$set(this.tableForm, e.vModel, e.defaultValue == undefined ? null : e
								.defaultValue);
						});
						this.defaultForm[field.vModel] = [obj];
					}
					this.defaultForm = JSON.parse(JSON.stringify(this.defaultData));
				});
				console.log(this.defaultForm, 'dmoajdajhdoajdo');

				this.fields.forEach(row => {
					if (this.formAuth[row.vModel] == 2 && row.required) {
						this.rules[row.vModel] = [{
							required: true,
							message: row.placeholder,
							trigger: 'blur'
						}]
					}
				})
				this.rules.comment = [{
					required: true,
					message: '请输入审批意见',
					trigger: 'blur'
				}]
				setTimeout(() => {
					this.applierChooseList.forEach(e => {
						this.approveData[e.paramKey] = [];
						this.selectUserData[e.paramKey] = '';
					});
				}, 100);
			},
			downloadFile(files) {
				console.log(files, '点进来了');
				tt.downloadFile({
					"url": global.BACKEND_URL + "/extension/file/download?fileName=" + files.fileName,
					success(res) {
						console.log(JSON.stringify(res), '下载成功');
					},
					fail(res) {
						console.log(`downloadFile fail: ${JSON.stringify(res)}`);
					}
				});
				let headers = {
					"Authorization": uni.getStorageSync('token'),
					"TenantId": 0,
				}
				console.log(headers);
				const downloadTask = tt.downloadFile({
					url: global.BACKEND_URL + "/extension/file/download?fileName=" + files.fileName,
					header: headers,
					success: res => {
						console.log('下载成功', res, 'dkoakdoa');
						if (res.statusCode === 200) {
							this.isShowProgress = false;
							console.log('下载成功');
						}
						let that = this;
						const filePath = res.tempFilePath;
						console.log(filePath, '路径---');
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							}
						});
			
					}
				})
			
				downloadTask.onProgressUpdate((res) => {
					if (res.progress > 0) {
						this.isShowProgress = true;
					}
					this.progress = res.progress;
					console.log('下载进度：' + res.progress);
					console.log('已下载长度：' + res.totalBytesWritten);
					console.log('文件总长度：' + res.totalBytesExpectedToWrite);
				})
			},
			
			getSelectDatas(e, option) {
				if (!!e) {
					let name = ''
					option.forEach(row => {
						if (row.value == e) {
							name = row.label
						}
					})
					console.log(e, option, name, 'getSelectDatas');
					return name;
				} else {
					return '暂未选择'
				}
			},
			confrimSingleTime(e) {
				this.editTableForm[this.formTag] = e.time;
				this.showSingletime = false;
			},
			cancelSingleTime(e) {
				this.showSingletime = false;
			},
			confrimTimeDuration(e) {
				this.editTableForm[this.formTag] = e.time;
				this.showdurationtime = false;
			},
			cancelTimeDuration(e) {
				this.showdurationtime = false;
			},
			beforeRead(item) {
				this.mark = item
				console.log(item, 'doakdoa');
			},
			comfirnSelect(e) {
				this.showSelect = false;
				this.editTableForm[this.formTag] = e.value[0].value
				console.log(e, '进来了吗', this.editTableForm[this.formTag]);
				this.stimer = new Date().getTime()
			},
			openSelect(e, o) {
				this.selectOptions = o
				this.formTag = e;
				this.showSelect = true;
				this.stimer = new Date().getTime()
			},
			getData(e) {
				console.log(e);
			},
			comfirnSingletime(e) {
				console.log(e);
				console.log(e, '====');
				this.showSingletime = false;
				this.editTableForm[this.formTag] = e.value + ':00'
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
			opendurationTime(e) {
				this.formTag = e;
				this.showdurationtime = true;
			},
			openSingleTime(e) {
				this.formTag = e;
				this.showSingletime = true;
			},
			openRangeDate(e) {
				this.mode = 'range';
				this.formTag = e;
				this.showRange = true;
			},
			openSingleDate(e) {
				this.mode = 'single';
				this.formTag = e;
				this.showSingle = true;
			},
			confirmSingleDate(e) {
				console.log(e, '这是啥');
				this.showSingle = false;
				this.editTableForm[this.formTag] = e + ' 00:00:00'

			},
			confirmRangeDate(e) {
				console.log(e, '这是啥');
				this.showRange = false;
				this.editTableForm[this.formTag] = [e[0] + ' 00:00:00', e[e.length - 1] + ' 00:00:00']
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				console.log(event, '---');
				let token = uni.getStorageSync('token')
				let that = this
				uni.uploadFile({
					url: global.BACKEND_URL + '/extension/file/upload', //仅为示例，非真实的接口地址
					fileType: 'image',
					filePath: event.file[0].url,
					name: 'file',
					header: {
						'Authorization': 'Bearer ' + token,
						'Content-Type': 'multipart/form-data',
						'TenantId': 0,
					},
					success: (uploadFileRes) => {
						if (!this.editTableForm[this.mark.vModel]) {
							this.editTableForm[this.mark.vModel] = [];
						}
						this.editTableForm[this.mark.vModel].push({
							fileUrl: JSON.parse(uploadFileRes.data).data[0].fileUrl,
							fileName: JSON.parse(uploadFileRes.data).data[0].encodedFileName,
							originalFileName: JSON.parse(uploadFileRes.data).data[0].fileName
						});
						console.log('返回的数据', JSON.parse(uploadFileRes.data).data[0])
					}
				});
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},

			getSelectData(e, istable, index, tableKey = null) {
				console.log(e, istable, index, tableKey, this.defaultForm, '--------');
				let param = {};
				if (e.param) {
					let that = this;
					e.param.forEach(p => {
						if (that.defaultForm[p.field]) {
							param[p.field] = that.defaultForm[p.field];
						}
						if (istable && !that.defaultForm[p.field]) {
							param[p.field] = that.defaultForm[tableKey][index][p.field];
						}
					});
				}
				console.log(param, '这是获取到得参数');
				if (e.dataSources === "dict") {
					uni.$u.http.request({
						url: global.BACKEND_URL + "/base/dict/query/" + e.api,
						method: 'POST',
						data: {},
						header: {
							Authorization: field.token,
							TenantId: 0
						}
					}).then(res => {
						if (res.data.code === "S00000") {
							let arr = [];
							res.data.data.forEach(e => {
								arr.push({
									label: e.dictName,
									value: e.dictCode,
								});
							});
							e.options = arr;
						}
					});
				} else if (e.dataSources === "api") {
					uni.$u.http.request({
						url: e.api,
						data: param,
						methods: 'POST',
						header: {
							Authorization: e.token
						},
						success: (res) => {
							e.options = res.data;
						}
					});
				}
			},
			checkData(required, val, p, vmodel) {
				if (this.isCheck && required && !val) {
					this.checkModel[vmodel] = true;
					return p;
				}
				this.checkModel[vmodel] = false;
				return "";
			},
			del(index) {
				if (this.defaultForm.length < 2) {
					uni.$u.toast("当前表格只有一行，无法删除");
					return;
				}
				this.defaultForm.splice(index, 1);
			},
			markfile(e, type = null, index = null) {
				if (type && index !== null) {
					this.mark = type;
					this.tableMark = e;
					this.tableIndex = index;
				} else {
					this.mark = e;
				}
			},
			onProgress(e) {},
			beforeUpload(e) {
				const isOver = e.size / 1024 / 1024 < this.mark.fileSize;
				// 限制文件上传大小
				if (!isOver) {
					this.$message.error('上传图片大小不能超过 ' + this.mark.fileSize + 'MB!');
					return false;
				}
			},
			beforeUploadTable(e) {
				const isOver = e.size / 1024 / 1024 < this.tableMark.fileSize;
				// 限制文件上传大小
				if (!isOver) {
					this.$message.error('上传图片大小不能超过 ' + this.tableMark.fileSize + 'MB!');
					return false;
				}
			},
			openChoose(e) {
				this.$refs.userchoose.dialogVisible = true;
				this.selectedProcessKey = e;
				this.$refs.userchoose.timer = new Date().getTime();
				this.approveData[this.selectedProcessKey].length && this.$refs.userchoose.setCheckedKeys(this.approveData[
					this.selectedProcessKey]);
			},
			// 条件回调
			getConditionData(e) {
				if (!e) {
					return false;
				}
				let arr = [];
				let users = [];
				e.forEach(r => {
					if (r.primaryCode.indexOf('org') === -1) {
						arr.push(r.primaryId);
						users.push(r.label);
					}
				});
				this.approveData[this.selectedProcessKey] = arr;
				this.selectUserData[this.selectedProcessKey] = users.join(' / ');
				this.userTimer = new Date().getTime();
				console.log(e, 'www', this.approveData, this.selectUserData);
			},
			submitForm(formName) {
				this.isCheck = true;
				setTimeout(() => {
					let checks = false;
					Object.keys(this.checkModel).forEach(e => {
						if (this.checkModel[e]) {
							checks = true;
						}
					});
					if (checks) {
						uni.$u.toast('您有必填项未填')
						return;
					}
					this.$refs.uForm.validate().then(res => {
						this.isEmpty = false;
						this.applierChooseList.forEach(e => {
							if (!this.approveData[e.paramKey].length) {
								this.isEmpty = true;
							}
						});
						if (this.isEmpty) {
							uni.$u.toast('请配置所有节点用户')
							return false;
						}
						this.loading = true;
						this.approveForm.procInstId = this.procInstId;
						this.approveForm.comment = this.defaultForm.comment;
						this.approveForm.param = this.defaultForm;
						delete this.approveForm.param.comment;
						this.$request(this.$api['workbench/approve'], this.approveForm, res => {
							this.$emit('approved', true);
							uni.$u.toast('审批完成')
							this.loading = false;
							uni.redirectTo({
								url: '/pages/approve/index'
							})
						}).catch(e => {
							this.loading = false;
						});
					}).catch(errors => {
						this.loading = false;
					})
				}, 100);
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			},
			handleRemoveFile(file) {
				let index = this.defaultForm[this.mark.vModel].findIndex(e => {
					return e.fileUrl == file.fileUrl;
				});
				this.defaultForm[this.mark.vModel].splice(index, 1);
			},
			getImgList(imgs) {
				let imgarr = [];
				imgs.forEach(e => {
					imgarr.push(e.fileUrl);
				});
				return imgarr;
			},
			handleRemoveTable(file) {
				console.log(file);
				let index = this.defaultForm[this.mark.vModel][this.tableIndex][this.tableMark.vModel].findIndex(e => {
					return e.fileUrl == file.response.data[0].fileUrl;
				});
				this.defaultForm[this.mark.vModel][this.tableIndex][this.tableMark.vModel].splice(index, 1);
				console.log(index, this.defaultForm[this.mark.vModel][this.tableIndex][this.tableMark.vModel]);
			},
			handleSuccessTable(e) {
				if (!this.defaultForm[this.mark.vModel][this.tableIndex][this.tableMark.vModel]) {
					this.defaultForm[this.mark.vModel][this.tableIndex][this.tableMark.vModel] = [];
				}
				this.defaultForm[this.mark.vModel][this.tableIndex][this.tableMark.vModel].push({
					fileUrl: e.data[0].fileUrl,
					fileName: e.data[0].fileName
				});
			},
			handlePreviewTable(file) {
				console.log(file);
			},
			handleRemove(file) {
				console.log(file);
				let index = this.defaultForm[this.mark.vModel].findIndex(e => {
					return e.fileUrl == file.response.data[0].fileUrl;
				});
				this.defaultForm[this.mark.vModel].splice(index, 1);
				console.log(index, this.defaultForm[this.mark.vModel]);
			},
			handleSuccess(e) {
				if (!this.defaultForm[this.mark.vModel]) {
					this.defaultForm[this.mark.vModel] = [];
				}
				this.defaultForm[this.mark.vModel].push({
					fileUrl: e.data[0].fileUrl,
					fileName: e.data[0].fileName
				});
			},
			handlePreview(file) {
				console.log(file);
			},
			handleExceed(files, fileList) {
				this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
			},
			beforeRemove(file, fileList) {
				return this.$confirm(`确定移除 ${ file.name }？`);
			}
		},

	}
</script>

<style>
	.fileStyle {
		width: 320rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		padding: 10upx 20upx;
		color: #fff;
		border: 1rpx solid #ccc;
		position: relative;
		margin: 10rpx 0;
		color: #666;
		border-radius: 6rpx;
		position: relative;
	}

	.btnstyle {
		width: auto;
		padding: 0 16rpx;
		height: 50rpx;
		float: right;
		line-height: 50rpx;
		text-align: center;
		border: 1rpx solid #f2f2f2;
		font-size: 26rpx;
		margin-right: 10rpx;
		border-radius: 10rpx;
		background-color: #11acf1;
		color: #ffffff;
	}
</style>